﻿// Decompiled with JetBrains decompiler
// Type: DnProcessSimulateCommands.CreateContinuousMFGFromCurve.CApCMCMfgContainerValidator
// Assembly: DnProcessSimulateCommands, Version=2402.0.0.890, Culture=neutral, PublicKeyToken=null
// MVID: A885D881-AEDF-447E-852A-6F13102E089C
// Assembly location: C:\Program Files\Tecnomatix_2402\eMPower\DotNetCommands\DnProcessSimulateCommands.dll

using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Resources;
using Tecnomatix.Engineering;
using Tecnomatix.Engineering.Ui;


namespace DnProcessSimulateCommands.CreateContinuousMFGFromCurve;

internal class CApCMCMfgContainerValidator : ITxValidator
{
  private const string _STRING_TABLE_LOCATION = "DnProcessSimulateCommands.CreateContinuousMFGFromCurve.CMCStringTable";
  private ResourceManager _resourceManager;

  public CApCMCMfgContainerValidator()
  {
    this._resourceManager = new ResourceManager("DnProcessSimulateCommands.CreateContinuousMFGFromCurve.CMCStringTable", this.GetType().Assembly);
    this.AllowedTypes = new List<Type>()
    {
      typeof (TxCompoundPart)
    };
  }

  public List<Type> AllowedTypes { get; set; }

  public ITxObject GetObject(string strText)
  {
    ITxObject itxObject1 = (ITxObject) null;
    TxObjectList txObjectList = (TxObjectList) null;
    if (!string.IsNullOrEmpty(strText))
      txObjectList = TxApplication.ActiveDocument.GetObjectsByName(strText);
    if (txObjectList != null && ((Collection<ITxObject>) txObjectList).Count > 0)
    {
      string errorMessage = (string) null;
      foreach (ITxObject itxObject2 in (Collection<ITxObject>) txObjectList)
      {
        if (this.IsValidObject(itxObject2, out errorMessage))
        {
          itxObject1 = itxObject2;
          break;
        }
      }
    }
    return itxObject1;
  }

  public string GetText(ITxObject obj)
  {
    string text = string.Empty;
    if (obj != null)
      text = obj.Name;
    return text;
  }

  public bool IsValidObject(ITxObject obj, out string errorMessage)
  {
    bool flag = false;
    errorMessage = (string) null;
    if (obj != null)
    {
      foreach (Type allowedType in this.AllowedTypes)
      {
        if (obj.GetType() == allowedType)
        {
          flag = true;
          break;
        }
      }
      if (!flag)
        errorMessage = this._resourceManager.GetString("CMC_INVALID_MFG_CONTAINER");
    }
    else
      flag = true;
    return flag;
  }

  public bool IsValidText(string text, out string errorMessage)
  {
    errorMessage = string.Empty;
    if (text == string.Empty)
      return true;
    ITxObject itxObject = this.GetObject(text);
    if (itxObject != null)
      return this.IsValidObject(itxObject, out errorMessage);
    errorMessage = this._resourceManager.GetString("CMC_INVALID_MFG_CONTAINER");
    return false;
  }
}
